package org.dtrd.modules.doctor.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.dtrd.modules.doctor.entity.bean.PatientServiceInfo;
import org.dtrd.modules.doctor.entity.bean.DoctorStatisticsItem;
import org.dtrd.modules.doctor.entity.po.DtrdRlDoctorPatient;
import org.dtrd.modules.patient.entity.bean.PatientH5ListInfo;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 医生-患者 Mapper 接口
 * </p>
 *
 * @author QR
 * @since 2021-12-17
 */
@Mapper
public interface DtrdRlDoctorPatientMapper extends BaseMapper<DtrdRlDoctorPatient> {

    /**
     * 查询服务于中与待服务的服务患者记录
     * @param doctorIdList
     * @param packageId
     * @return
     */
    List<PatientServiceInfo> getPatientInfomationInDoctorService(@Param("doctorIdList") List<Integer> doctorIdList,
                                                                 @Param("packageId") Integer packageId);

    DtrdRlDoctorPatient getDpRlByPatientId(@Param("patientId") Integer patientId, @Param("doctorId") Integer doctorId);

    void updateChatroomIdByDoctorIdPatientId(@Param("chatRoomId") String chatRoomId, @Param("patientId") Integer patientId, @Param("doctorId") Integer doctorId);

    /**
     * 关注或者取消关注患者
     *
     * @param patientsCollected
     * @param patientId
     * @param doctorId
     * @return
     */
    Integer updateConcernState(@Param("concern") Integer patientsCollected, @Param("patientId") Integer patientId, @Param("doctorId") Integer doctorId);

    List<DtrdRlDoctorPatient> getRelativeRecords();

    /**
     * 查询医生重点关注患者数目
     *
     * @param doctorId
     * @return
     */
    Integer getConcernCountByDoctorId(@Param("doctorId") Integer doctorId);

    /**
     * 患者总数
     *
     * @param doctorId
     * @param date
     * @param relationTypes
     * @return
     */
    List<DoctorStatisticsItem> getPatientCount(@Param("doctorId") Integer doctorId, @Param("date") String date, @Param("relationTypes") String relationTypes);

    List<DoctorStatisticsItem> getPatientCountV2(@Param("doctorIdList") List<Integer> teamDoctorIdList, @Param("date") String date, @Param("relationTypes") String relationTypes);

    /**
     * 分页查询医患关联患者列表
     *
     * @param page
     * @param doctorIdList      医生ID
     * @param recordDate    纪录日期
     * @param relationTypes 医患关系类型
     * @param type          请求类型
     * @return
     */
    IPage<PatientH5ListInfo> pageRelationPatientList(IPage<PatientH5ListInfo> page, @Param("doctorIdList") List<Integer> doctorIdList, @Param("date") String recordDate, @Param("relationTypes") String relationTypes, @Param("type") Integer type);

    /**
     * 分页查询重点关注患者
     *
     * @param page
     * @param doctorId
     * @return
     */
    IPage<PatientH5ListInfo> pageConcernPatientList(IPage<PatientH5ListInfo> page, @Param("doctorId") Integer doctorId);

    /**
     * @param page
     * @param doctorIdList
     * @param relationTypes
     * @param subType       子类型 1 已绑定设备 2 未绑定
     * @return
     */
    IPage<PatientH5ListInfo> pageScanRelationPatientList(IPage<PatientH5ListInfo> page,
                                                         @Param("doctorIdList") List<Integer> doctorIdList,
                                                         @Param("relationTypes") String relationTypes,
                                                         @Param("subType") Integer subType);

    void deleteRecordByPatientIds(@Param("patientIdList") Set<Integer> patientIds);

    /**
     * 计算服务中患者总数
     *
     * @param doctorId
     * @return
     */
    List<DoctorStatisticsItem> countServingPatient(@Param("doctorId") Integer doctorId);

    List<DoctorStatisticsItem> countServingPatientV2(@Param("doctorIdList") List<Integer> doctorIdList);

    /**
     * 计算联网血糖仪患者总数
     *
     * @param doctorId
     * @return
     */
    List<DoctorStatisticsItem> countBindDevicePatient(@Param("doctorId") Integer doctorId);

    List<DoctorStatisticsItem> countBindDevicePatientV2(@Param("doctorIdList") List<Integer> doctorIdList);

    List<Integer> listPatientIdsByDoctorId(@Param("doctorIdList") List<Integer> doctorIdList);

}
